package com.wingsfrog.puzzle.controller.filter;

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
@Profile("prod")
public class ProdCrosAllowedFilter implements Filter {
    public void init(FilterConfig filterConfig) throws ServletException {}

    public void doFilter(ServletRequest request, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
        HttpServletResponse response = (HttpServletResponse)servletResponse;

        response.setHeader("Access-Control-Allow-Origin", "http://wingsfrog.com");
        response.setHeader("Access-Control-Allow-Methods", "GET,POST,PUT,PATCH,DELETE,OPTIONS");
        response.setHeader("Access-Control-Max-Age", "3600");
        response.setHeader("Access-Control-Allow-Headers", "Origin,No-Cache," +
                "X-Requested-With,If-Modified-Since,Pragma,Last-Modified," +
                "Cache-Control,Expires,Content-Type,X-E4M-With");
        response.addHeader("Access-Control-Allow-Credentials", "true");
//        response.setContentType("application/json;charset=UTF-8");
        response.setCharacterEncoding("UTF-8");
        chain.doFilter(request, servletResponse);
    }

    public void destroy() {

    }
}
